<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用戶管理</el-breadcrumb-item>
      <el-breadcrumb-item>用戶列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="primary">添加用戶</el-button>
        </el-col>
      </el-row>
<!--      繪製表格區域-->
      <el-table   :data="tableData.users"   style="width: 100%" border>
        <el-table-column     prop="username"    label="姓名"      >     </el-table-column>
        <el-table-column     prop="role_name"    label="角色"     >      </el-table-column>
        <el-table-column     prop="mobile" label="電話">      </el-table-column>
        <el-table-column     label="狀態" width="80px">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.mg_state"></el-switch>
          </template>
        </el-table-column>
        <el-table-column     label="操作" width="180px">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini"></el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
            <el-tooltip effect="dark" content="權限修改" placement="top" :enterable="false">
              <el-button type="warning" icon="el-icon-setting" size="mini"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
<!--      分頁區域-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="userquery.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="userquery.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'users.vue',
  data() {
    return {
      tableData: [],
      userquery: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      isadmin: true
    }
  },
  created() {
    this.getUserList(this.userquery)
  },
  methods: {
    async getUserList(userquery) {
      const { data: res } = await this.$http.get('users', { params: this.userquery })
      console.log(res)
      this.tableData = res.data
    },
    handleSizeChange(newsize) {
      // console.log(newsize)
      this.userquery.pagesize = newsize
      this.getUserList(this.userquery)
    },
    handleCurrentChange(newpage) {
      // console.log(newpage)
      this.userquery.pagenum = newpage
      this.getUserList(this.userquery)
    }
  }
}
</script>

<style scoped>

</style>
